<template>

    <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="">
            <el-input placeholder="跟单编号" clearable />
        </el-form-item>
        <el-form-item label="">
            <el-input placeholder="单据编码" clearable />
        </el-form-item>
        <el-form-item label="">
            <el-input placeholder="供应商" clearable />
        </el-form-item>
        <el-form-item label="">
            <el-input placeholder="物料编码" clearable />
        </el-form-item>
        <el-form-item label="">
            <el-input placeholder="物料名称" clearable />
        </el-form-item>
        <el-form-item label="">
            <div class="block">
                <el-date-picker v-model="value2" type="daterange" unlink-panels range-separator="-"
                    start-placeholder="开始日期" end-placeholder="结束日期" :shortcuts="shortcuts" />
            </div>
        </el-form-item>



        <el-form-item>
            <el-button type="primary" @click="GetSuppliers()">搜索</el-button>
        </el-form-item>


    </el-form>
    <el-button type="primary" :icon="List" @click="">查询所有</el-button>
    <el-button type="primary" :icon="Plus" plain @click="router.push('/PurchasingManagement/PurchaseOrdeAdd')">新增</el-button>
    <el-button type="primary" @click="GetOut()" :icon="Upload">导出</el-button>


    <el-empty description="暂无数据" v-show="suppliers.length == 0" />
    <el-table :data="suppliers" stripe style="width: 100%" v-show="suppliers.length != 0">
        <el-table-column prop="purchaseOrderId" label="序号" />
        <el-table-column prop="receiptNum" label="单据编码">
            <template v-slot="scope">
                <a @click="tiaozhuan(scope.row.purchaseOrderId)">{{ scope.row.receiptNum }}</a>
            </template>
        </el-table-column>
        <el-table-column prop="receiptState" label="单据状态" />
        <el-table-column prop="system" label="供应商" />
        <el-table-column prop="materialName" label="物料名称" />
        <el-table-column prop="materialCode" label="物料编码" />
        <el-table-column prop="approvalDate" label="需求日期">
            <template #default="scope">
                {{ scope.row.requirementDate.substring(0, 10) }}
            </template>
        </el-table-column>
        <el-table-column prop="arrivalQuantity" label="采购数量" />
        <el-table-column prop="receiptDate" label="单据日期">
            <template #default="scope">
                {{ scope.row.receiptDate.substring(0, 10) }}
            </template>
        </el-table-column>

    </el-table>

    <div>
        <tr>
            <td>
                <el-pagination v-model:current-page="formInline.pageIndex" v-model:page-size="formInline.pageSize"
                    :page-sizes="[10, 20, 30, 40, 50]" :background="true" layout="total, slot, prev, pager, next"
                    :total="formInline.totalCount" @size-change="handleSizeChange"
                    @current-change="handleCurrentChange">
                </el-pagination>
            </td>
            <td>
                <el-pagination v-model:current-page="formInline.pageIndex" v-model:page-size="formInline.pageSize"
                    :page-sizes="[10, 20, 30, 40, 50]" :background="true" layout="slot, sizes, jumper"
                    :total="formInline.totalCount" @size-change="handleSizeChange"
                    @current-change="handleCurrentChange">
                </el-pagination>
            </td>
        </tr>
    </div>
</template>

<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import axios from 'axios';
import { Plus, Upload, List } from '@element-plus/icons-vue'
import type { TabsPaneContext } from 'element-plus'

const apiurls = import.meta.env.VITE_APP_API_URL_BasicInformationCommon;//5176
const router = useRouter()

const add = () => {
    router.push('/PurchasingManagement/PurchaseOrdeAdd')
}

const tiaozhuan = (purchaseOrderId: any) => {
    router.push({
        path: '/PurchasingManagement/PurchaseOrdeEdit',
        query: {
            purchaseOrderId: purchaseOrderId
        }
    })
}


onMounted(() => {
    GetSuppliers()
});
const value2 = ref('')

const GetOut = () => {
    location.href = apiurls + '/api/Suppliers/ShoppingExcelHandle';
}


const shortcuts = [
    {
        text: '最近一周',
        value: () => {
            const date = new Date()
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
            return date
        },

    },
    {
        text: '最近一个月',
        value: () => {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            return [start, end]
        },
    },
    {
        text: '最近三个月',
        value: () => {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            return [start, end]
        },
    },
]

const formInline = reactive({
    pageIndex: 1,
    pageSize: 10,
    pageCount: 0,
    totalCount: 0,

})


const handleClick = (tab: TabsPaneContext, event: Event) => {
    console.log(tab, event)
}
//销售订单单据列表
const suppliers: any = ref([]);
const GetSuppliers = () => {
    axios
        .get(
            apiurls + '/api/Suppliers/PurchaseOrderList',
            {
                params: {
                    pageIndex: formInline.pageIndex,
                    pageSize: formInline.pageSize,
                }
            }
        )
        .then((res) => {
            console.log(res.data.data);
            suppliers.value = res.data.data.list;
            formInline.pageCount = res.data.data.totalPage;
            formInline.totalCount = res.data.data.totalCount;
        })
        .catch((err) => {
            console.log(err);
        });
};

// const GetSuppliers1 = () => {
//     axios
//         .get(
//             'http://localhost:5227/api/SalesOrder/SearchSalesOrderDetail',
//             {
//                 params: {
//                     documentNumber: '',
//                     itemName: '',
//                     salesStaff: '',
//                     customerProfileName: '',
//                     pageIndex: 1,
//                     pageSize: 10,
//                 }
//             }
//         )
//         .then((res) => {
//             console.log(res.data.data);
//             suppliers.value = res.data.data;
//             formInline.pageCount = res.data.pageCount;
//             formInline.totalCount = res.data.totalCount;
//         })
//         .catch((err) => {
//             console.log(err);
//         });
// };

//分页
const handleSizeChange = (val: number) => {
    formInline.pageSize = val
    GetSuppliers()
}
const handleCurrentChange = (val: number) => {
    formInline.pageIndex = val
    GetSuppliers()
}



const formLabelWidth = '140px'

</script>

<style>
.demo-tabs>.el-tabs__content {
    padding: 32px;
    color: #6b778c;
    font-size: 32px;
    font-weight: 600;
}
</style>
<style scoped>
.demo-date-picker {
    display: flex;
    width: 100%;
    padding: 0;
    flex-wrap: wrap;
}

.demo-date-picker .block {
    padding: 30px 0;
    text-align: center;
    border-right: solid 1px var(--el-border-color);
    flex: 1;
}

.demo-date-picker .block:last-child {
    border-right: none;
}

.demo-date-picker .demonstration {
    display: block;
    color: var(--el-text-color-secondary);
    font-size: 14px;
    margin-bottom: 20px;
}
</style>